
<!--#INCLUDE FILE="conn.asp"-->
<!-- #include file="comSub.asp" -->
<!-- #include file="function.asp" -->
<!-- #include file="function_charCode.asp" -->
<!-- #include file="UBB/myUBB.asp" -->

<%call tslt_username_error_Exit()%>

<html>
<SCRIPT language=JavaScript>
<!--
      function SelfSize(){
           self.resizeTo(320,280);
           self.moveTo(340,200);
      }

      var timeout;
      function window_onload(){
           timeout=setTimeout(MYclose,4000);
      }
      function MYclose(){
          self.close();
      }
-->
</SCRIPT>

<body onload="SelfSize();window_onload();">

<%
if request("isDelReply") = "ok" then
       call UserDelReplyScore(request("repId"))
       call deletereply(request("repId"),request("AId"))
       call MyPrompt()             
end if
if request("delallreply")<>"" then
       call delallreply(request("delallreply"))
       call MyPrompt()   
end if
if request("isModifyReply") = "ok" then
       call modifyreply()    
       call MyPrompt2()        
end if    
if request("isAddCollection") = "ok" then
       if session("tslt_username")<>"" then
              call AddCollection(request("articleId"))    
              call MyPrompt()        
       end if 
end if    
if request("isDelCollection") = "ok" then
       if session("tslt_username")<>"" then
              call DelCollection(request("articleId"))    
              call MyPrompt()        
       end if 
end if    
if request("isFromCollection") = "ok" then
       call FromCollection()
       call MyPrompt()     
end if
If request("isLockReply")="ok" Then 
    Call myLockReply(request("repId"))
    Call MyPrompt()             
End If
If request("isCancelLR")="ok" Then 
    Call myCancelLR(request("repId"))
    Call MyPrompt()             
End If
%>

<p><center><input type="reset" value="ر" OnClick="self.close();">
</body>
</html>
<%
Call conn_Nothing()

sub UserDelReplyScore(aaa)   
       dim Rs,Sql 
       set Rs=server.createobject("adodb.recordset")
       Sql = "Select * From reply where cstr(id)='" & aaa & "'"
       Rs.Open Sql, Conn,1,2
                if not Rs.eof then
                          dim replyuser
                           replyuser = Rs("reply_human")
                           dim ScoreRs,ScoreSQL
                           Set ScoreRs=Server.CreateObject("ADODB.RecordSet")
                           ScoreSQL="Select * from ts_userinfo where username = '" & replyuser &"'"
                           ScoreRs.open ScoreSQL,Conn,1,2
                                 if not ScoreRs.eof then
                                         dim  DelReplyScore2
                                         DelReplyScore2= ScoreRs("UserIntegral") + UserScore("DelReplyScore")     
                                         ScoreRs("UserIntegral") = DelReplyScore2
                                         ScoreRs.update
                                 end if
                           ScoreRs.close
                           set ScoreRs=nothing
                end if
         Rs.close
         set Rs=nothing
end sub

sub deletereply(aaa,isAId)      
       dim sql
       dim Rs
      set Rs=server.createobject("adodb.recordset")
      Dim rSavePathFileName
      Sql = "SELECT r_SavePathFileName FROM reply WHERE cstr(id)= '" & aaa & "'"
      Rs.Open Sql, Conn, 0, 1
            do while not rs.eof
                  If Not Rs.Eof Then
                        r_SavePathFileName2 = Rs("r_SavePathFileName")
                  End If
                  Dim aSavePathFileName
                  aSavePathFileName = Split(r_SavePathFileName2, "|")
                  Dim j
                  For j = 0 To UBound(aSavePathFileName)
                       Call DoDelFile(aSavePathFileName(j))
                  Next
                  rs.movenext
           loop
           conn.execute("delete FROM reply WHERE cstr(id)='" & aaa & "'")
      RS.close
      set Rs=Nothing
      set Rs=conn.execute("SELECT AllReplyCount FROM article where ID = "&isAId)
          conn.Execute ("update article set AllReplyCount='"&(Rs("AllReplyCount")-1)&"' where ID = "&isAId)
      RS.close
      set Rs=Nothing
      call AllReplySize(isAId)
End Sub

sub delallreply(aaa)     
       dim Rs,sql
       set Rs=server.createobject("adodb.recordset")
       Dim rSavePathFileName
       Sql = "SELECT r_SavePathFileName FROM reply WHERE cstr(reply_id)= '" & aaa & "'"
       Rs.Open Sql, Conn, 0, 1
            do while not rs.eof
                  If Not Rs.Eof Then
                        r_SavePathFileName2 = Rs("r_SavePathFileName")
                  End If
                  Dim aSavePathFileName
                  aSavePathFileName = Split(r_SavePathFileName2, "|")
                 Dim j
                 For j = 0 To UBound(aSavePathFileName)
                        Call DoDelFile(aSavePathFileName(j))
                 Next
                rs.movenext
           loop
           conn.execute("delete FROM reply WHERE cstr(reply_id)='" & aaa & "'")
      RS.close
      set Rs=Nothing
      conn.Execute ("update article set AllReplyCount=0 where ID = "&aaa)
      call AllReplySize(request("delallreply"))
End Sub

sub modifyreply()          
       Dim ModifyReplyid,boardid,ModifyReplyid_SavePath,sendip
       ModifyReplyid = Request("ModifyReplyid")
       ModifyReplyid_SavePath = Request("ModifyReplyid_SavePath")
       sendip = userIP() 
       dim mr_content2
       if IsEWebYesNo()=true then
             For i = 1 To Request.Form("mr_content"&ModifyReplyid).Count
                     mr_content2= mr_content2 & Request.Form("mr_content"&ModifyReplyid)(i)
             Next  
       end if
       if IsEWebYesNo()=false then
              mr_content2 = Request.Form("mr_content"&ModifyReplyid)
			  If session("tslt_useridentity")<>1 And session("tslt_useridentity")<>2 Then
                  mr_content2 = myReplace(mr_content2)
                  mr_content2 = UBBCode(mr_content2)
			  Else
			      mr_content2 = UBBCode(mr_content2)
		      End If 
       end if
       Dim sSavePathFileName
       sSavePathFileName = GetSafeStr(Request.Form("mr_savepathfilename"&ModifyReplyid))
       if ModifyReplyid_SavePath<>"" then
              if sSavePathFileName<>"" then
                     ModifyReplyid_SavePath = ModifyReplyid_SavePath &"|"& sSavePathFileName
              else
                     ModifyReplyid_SavePath = ModifyReplyid_SavePath
              end if
       else
             if sSavePathFileName<>"" then
                  ModifyReplyid_SavePath = sSavePathFileName
             else
                  ModifyReplyid_SavePath= ""
             end if
       end if
       if instr(ModifyReplyid_SavePath,"|")=0 then 
             if instr(mr_content2,ModifyReplyid_SavePath)=0 then 
                   ModifyReplyid_SavePath=""
             else
                   ModifyReplyid_SavePath=ModifyReplyid_SavePath
             end if
       else
             dim rrr
             rrr=""
             arrays=Split(ModifyReplyid_SavePath,"|")
             for j=0 to ubound(arrays)
                    if instr(mr_content2,arrays(j))=0 then
                          arrays(j)=""
                    else
                          arrays(j)= "|" & arrays(j)
                    end if
                    rrr=rrr &arrays(j)
             next
               ModifyReplyid_SavePath=rrr
       end if
       if Left(ModifyReplyid_SavePath,1)="|" then
             ModifyReplyid_SavePath=right(ModifyReplyid_SavePath,Len(ModifyReplyid_SavePath)-1)
       end if
       dim ContentAllSize
       ContentAllSize = Len(mr_content2) + FileContentSize(ModifyReplyid_SavePath)
       dim ContentAllSize2
       ContentAllSize2 = FileContentSize2(Len(mr_content2)+ FileContentSize(ModifyReplyid_SavePath))
       Dim RS,strSql
       Set RS = Server.CreateObject("ADODB.Recordset")
       strSql = "SELECT * FROM  reply WHERE ID=" & ModifyReplyid
       Rs.Open strSql, Conn, 1, 3
             If Not Rs.Eof Then
                    RS("reply_time") = now()
                    RS("reply_content") = mr_content2
                    RS("contentsize") = ContentAllSize
                    RS("contentsize2") = ContentAllSize2 
                    RS("IP") = sendip
                    RS("r_SavePathFileName") = ModifyReplyid_SavePath
                    RS.Update
             end if
	         Dim AId     
             AId=RS("reply_id")   
        RS.close
        Set RS = Nothing
       call AllReplySize(AId) 
end sub

Sub MyPrompt()
        Response.write "<SCRIPT language=Javascript>passwords(promptInfo_11_Delreply(0))</SCRIPT>"
End Sub

Sub MyPrompt2()
        Response.write "<SCRIPT language=Javascript>passwords(promptInfo_11_Delreply(1))</SCRIPT>"
End Sub

function IsEWebYesNo()        
        dim rs,Sql                  
        Sql = "select * from option1"
        set rs=conn.execute(Sql)
              IsEWebYesNo=rs("IsEWeb")
        rs.close
        set rs=nothing
end function

Sub AddCollection(articleId)
       Dim Sql,Rs
       Sql="select collection From ts_userinfo where username='" & session("tslt_username") & "'"
       set Rs=conn.Execute(sql)
                  Dim collection2
                  collection2 = Rs("collection")
                   if collection2<>"" then
                          collection2= collection2 &articleId& "|"
                          conn.Execute("update ts_userinfo set collection='"&collection2&"' where username='"&session("tslt_username")&"'")
                   else
                          collection2= "|" & articleId & "|"
                          conn.Execute("update ts_userinfo set collection='"&collection2&"' where username='"&session("tslt_username")&"'")
                   end if
        RS.close              
        Set RS = Nothing
End Sub

Sub DelCollection(articleId)
       Dim Sql,Rs
       Sql="select collection From ts_userinfo where username='" & session("tslt_username") & "'"
       set Rs=conn.Execute(sql)
                  Dim collection2
                  collection2 = Rs("collection")
                   if collection2<>"" then
                          if instr(collection2,articleId)<>false then
                                 collection2=replace(collection2,"|"&articleId&"|","|")
                                 conn.Execute("update ts_userinfo set collection='"&collection2&"' where username='"&session("tslt_username")&"'")
                          end if
                           if collection2="|" then
                                 conn.Execute("update ts_userinfo set collection='' where username='"&session("tslt_username")&"'")
                          end if
                   end if
        RS.close              
        Set RS = Nothing
End Sub

Sub FromCollection()
        Dim RS,SQL
        Set RS=Server.CreateObject("ADODB.RecordSet")
        SQL="Select id From article"
        RS.open SQL,Conn,1,2
               do while not RS.eof
                      n=trim(cstr(RS("id")))
                      if request.form(n)="on" then
                             select case request("act")
                             case 1                            
                                     Dim Sql1,Rs1
                                     Sql1="select collection From ts_userinfo where username='" & session("tslt_username") & "'"
                                     set Rs1=conn.Execute(sql1)
                                           Dim collection2
                                           collection2 = Rs1("collection")
                                            if collection2<>"" then
                                                 if instr(collection2,n)<>false then
                                                          collection2=replace(collection2,"|"&n&"|","|")
                                                          conn.Execute("update ts_userinfo set collection='"&collection2&"' where username='"&session("tslt_username")&"'")
                                                          collection2=collection2 & n &"|"
                                                          conn.Execute("update ts_userinfo set collection='"&collection2&"' where username='"&session("tslt_username")&"'")
                                                   end if
                                            end if
                                      RS1.Close
                                      Set RS1 = Nothing
                             case 2                                              
                                     Dim Sql2,Rs2
                                     Sql2="select collection From ts_userinfo where username='" & session("tslt_username") & "'"
                                     set Rs2=conn.Execute(sql2)        
                                            collection2 = Rs2("collection")
                                             if collection2<>"" then
                                                    if instr(collection2,n)<>false then
                                                            collection2=replace(collection2,"|"&n&"|","|")
                                                            conn.Execute("update ts_userinfo set collection='"&collection2&"' where username='"&session("tslt_username")&"'")
                                                    end if
                                                     if collection2="|" then
                                                            conn.Execute("update ts_userinfo set collection='' where username='"&session("tslt_username")&"'")
                                                     end if
                                             end if
                                      RS2.Close
                                      Set RS2 = Nothing
                             case 3                        
                                     conn.Execute("update ts_userinfo set collection='' where username='"&session("tslt_username")&"'")
                             end select
                      end if
                      rs.movenext
               loop 
        RS.Close
        Set RS = Nothing
End Sub

Sub myLockReply(aaa)
       Dim Rs,Sql 
       Set Rs=server.createobject("adodb.recordset")
       Sql = "Select lockReply From reply where cstr(id)='" & aaa & "'"
       Rs.Open Sql, Conn,1,1
           conn.Execute("update reply set lockReply=True WHERE cstr(id)= '" & aaa & "'")
       Rs.close
       Set Rs=Nothing
End Sub 

Sub myCancelLR(aaa)    
       Dim Rs,Sql 
       Set Rs=server.createobject("adodb.recordset")
       Sql = "Select lockReply From reply where cstr(id)='" & aaa & "'"
       Rs.Open Sql, Conn,1,1
           conn.Execute("update reply set lockReply=false WHERE cstr(id)= '" & aaa & "'")
       Rs.close
       Set Rs=Nothing
End Sub 
%>

